package org.batyrov.equery.action.admin;

import org.batyrov.equery.action.BaseAction;
import org.batyrov.equery.action.Const;
import org.batyrov.equery.bean.Service;
import org.batyrov.equery.bean.User;

import java.util.Collection;

/**
 * Created by IntelliJ IDEA.
 * User: admin
 * Date: 25.07.2009
 * Time: 0:02:23
 * To change this template use File | Settings | File Templates.
 */
public class RemoveService  extends BaseAction {
    private long id;
    private Collection<Service> services;

    public Collection<Service> getServices() {
        return services;
    }

    public void setServices(Collection<Service> services) {
        this.services = services;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    @Override
    public String execute() throws Exception {
        super.execute();
        Service service = em.find(Service.class, id);
        if (service == null){
            addActionError(getText("service_not_found"));
            services = dao.getAllService();
            return Const.ERROR;
        }
        if (dao.remove(service)){
            return Const.SUCCESS;
        }
        services = dao.getAllService();
        addActionError(getText("cannot_remove_service"));
        return Const.ERROR;
    }
}
